package li_xiang;

/**
 * @DESCRIPER:    实现栈的增删，仅在栈顶进行插入和删除,另一端栈底
 * @AUTHOR:lixiang
 * @PHONE:15226392261
 * @EMIAL:1214336214@qq.COM
 * @DATE: 2021-01-23 16:59
 * @PARAMDESCRIPER:
 * @OUTPARAMDESCRIPER:
 */
public class LI_XIANG_23_Q1 {

    // 定义一个栈类
    static class ArrayStack{
        private Object[] arr;
        private int top = -1;
        private int bottom;
        private int maxsize = 20;

        public ArrayStack() {
            arr = new Object[maxsize];
        }

        // 判断栈是否为满
        public Boolean isFull(){
            return top == maxsize - 1;
        }

        // 判断栈是否为空
        public Boolean isEmpty(){
            return top == -1;
        }

        // 进栈
        public void push(int n){
            if (isFull()){
                System.out.println("栈已满0.0");
            }
            top++;
            arr[top] = n;

        }

        // 出栈
        public void pop(){
            Object[] arrDelete = new Object[arr.length];
            if (isEmpty()){
                System.out.println("栈为空0.0");
            }
//        arrDelete[top] = arr[top];
            arr[top] = null;
            top--;

        }

        public void showStack(){
            if (isEmpty()){
                System.out.println("栈为空0.0");
            }
            else {
                for (int i = 0; i < arr.length; i++){
                    System.out.println(arr[i]);
                }
            }
        }
    }

    public static void main(String[] args) {
        ArrayStack arrayStack = new ArrayStack();
        for (int i = 0; i < 20; i++){
            arrayStack.push(i);
        }
//        arrayStack.push(1);

        arrayStack.showStack();
        arrayStack.pop();
        arrayStack.pop();
        arrayStack.showStack();
        arrayStack.push(18);
        arrayStack.showStack();
    }

}

